package com.woniuxy.ticket.controller;

import com.woniuxy.ticket.model.dto.AddDto;
import com.woniuxy.ticket.service.OrdersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/orders")
public class OrderController {
    @Autowired
    private OrdersService ordersService;

    @GetMapping("/All")
    public ResponseEntity<Map<String, Object>> getAllOrders(@RequestParam int pageNum, @RequestParam int pageSize) {
        Map<String, Object> response = ordersService.getAllOrders(pageNum, pageSize);
        return ResponseEntity.ok(response);
    }


    @PostMapping("/add")
    public ResponseEntity<String> addOrder(@RequestBody AddDto addDto) {
        String result = ordersService.addOrder(addDto);
        if ("success".equals(result)) {
            return ResponseEntity.ok("添加成功");
        } else {
            return ResponseEntity.badRequest().body(result);
        }
    }



}
